home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing.plaf.basic;
-
- import com.sun.java.swing.JButton;
- import com.sun.java.swing.JComponent;
- import com.sun.java.swing.JScrollBar;
- import com.sun.java.swing.LookAndFeel;
- import com.sun.java.swing.SwingConstants;
- import com.sun.java.swing.Timer;
- import com.sun.java.swing.UIManager;
- import com.sun.java.swing.plaf.ComponentUI;
- import com.sun.java.swing.plaf.ScrollBarUI;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import java.awt.Insets;
- import java.awt.LayoutManager;
- import java.awt.Rectangle;
- import java.io.Serializable;
-
- public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager, Serializable, SwingConstants {
- private static final Dimension minimumThumbSize = new Dimension(8, 8);
- private static final Dimension maximumThumbSize = new Dimension(4096, 4096);
- private static Color thumbHighlightColor;
- private static Color thumbLightShadowColor;
- private static Color thumbDarkShadowColor;
- private static Color thumbColor;
- private static Color trackColor;
- private static Color trackHighlightColor;
- private static boolean scrollBarColorsInitialized = false;
- protected JScrollBar scrollbar;
- protected JButton incrButton;
- protected JButton decrButton;
- protected boolean isDragging;
- protected TrackListener trackListener;
- protected ArrowButtonListener buttonListener;
- protected ModelListener modelListener;
- private Rectangle thumbRect;
- private Rectangle trackRect;
- protected int trackHighlight;
- protected static final int NO_HIGHLIGHT = 0;
- protected static final int DECREASE_HIGHLIGHT = 1;
- protected static final int INCREASE_HIGHLIGHT = 2;
- protected ScrollListener scrollListener;
- protected Timer scrollTimer;
-
- public void addLayoutComponent(String name, Component child) {
- }
-
- protected void configureScrollBarColors() {
- if (!scrollBarColorsInitialized) {
- thumbHighlightColor = UIManager.getColor("ScrollBar.thumbHighlight");
- thumbLightShadowColor = UIManager.getColor("ScrollBar.thumbLightShadow");
- thumbDarkShadowColor = UIManager.getColor("ScrollBar.thumbDarkShadow");
- thumbColor = UIManager.getColor("ScrollBar.thumb");
- trackColor = UIManager.getColor("ScrollBar.track");
- trackHighlightColor = UIManager.getColor("ScrollBar.trackHighlight");
- scrollBarColorsInitialized = true;
- }
-
- }
-
- protected JButton createDecreaseButton(int orientation) {
- return new BasicArrowButton(orientation);
- }
-
- protected JButton createIncreaseButton(int orientation) {
- return new BasicArrowButton(orientation);
- }
-
- public static ComponentUI createUI(JComponent c) {
- return new BasicScrollBarUI();
- }
-
- public Dimension getMaximumSize(JComponent c) {
- return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
- }
-
- protected Dimension getMaximumThumbSize() {
- return maximumThumbSize;
- }
-
- public Dimension getMinimumSize(JComponent c) {
- return this.getPreferredSize(c);
- }
-
- protected Dimension getMinimumThumbSize() {
- return minimumThumbSize;
- }
-
- public Dimension getPreferredSize(JComponent c) {
- return this.scrollbar.getOrientation() == 1 ? new Dimension(16, 48) : new Dimension(48, 16);
- }
-
- protected Rectangle getThumbBounds() {
- return this.thumbRect;
- }
-
- protected Rectangle getTrackBounds() {
- return this.trackRect;
- }
-
- public void installUI(JComponent c) {
- this.scrollbar = (JScrollBar)c;
- this.thumbRect = new Rectangle(0, 0, 0, 0);
- this.trackRect = new Rectangle(0, 0, 0, 0);
- this.trackHighlight = 0;
- switch (((JScrollBar)c).getOrientation()) {
- case 0:
- this.incrButton = this.createIncreaseButton(3);
- this.decrButton = this.createDecreaseButton(7);
- break;
- case 1:
- this.incrButton = this.createIncreaseButton(5);
- this.decrButton = this.createDecreaseButton(1);
- }
-
- this.scrollbar.setLayout(this);
- this.scrollbar.add(this.incrButton);
- this.scrollbar.add(this.decrButton);
- this.trackListener = new TrackListener(this);
- this.buttonListener = new ArrowButtonListener(this);
- this.modelListener = new ModelListener(this);
- this.scrollbar.addMouseListener(this.trackListener);
- this.scrollbar.addMouseMotionListener(this.trackListener);
- this.scrollbar.getModel().addChangeListener(this.modelListener);
- if (this.incrButton != null) {
- this.incrButton.addMouseListener(this.buttonListener);
- }
-
- if (this.decrButton != null) {
- this.decrButton.addMouseListener(this.buttonListener);
- }
-
- this.scrollbar.setEnabled(this.scrollbar.isEnabled());
- this.scrollbar.setOpaque(true);
- this.scrollListener = new ScrollListener(this);
- this.scrollTimer = new Timer(100, this.scrollListener);
- this.scrollTimer.setInitialDelay(300);
- LookAndFeel.installBorder(this.scrollbar, "ScrollBar.border");
- this.configureScrollBarColors();
- }
-
- public void layoutContainer(Container scrollbarContainer) {
- if (!this.isDragging) {
- JScrollBar scrollbar = (JScrollBar)scrollbarContainer;
- switch (scrollbar.getOrientation()) {
- case 0:
- this.layoutHScrollbar(scrollbar);
- break;
- case 1:
- this.layoutVScrollbar(scrollbar);
- }
-
- }
- }
-
- protected void layoutHScrollbar(JScrollBar sb) {
- Dimension sbSize = ((Component)sb).getSize();
- Insets sbInsets = ((JComponent)sb).getInsets();
- int itemH = sbSize.height - (sbInsets.top + sbInsets.bottom);
- int itemY = sbInsets.top;
- int decrButtonW = this.decrButton.getPreferredSize().width;
- int decrButtonX = sbInsets.left;
- int incrButtonW = this.incrButton.getPreferredSize().width;
- int incrButtonX = sbSize.width - (sbInsets.right + incrButtonW);
- int sbInsetsW = sbInsets.left + sbInsets.right;
- int sbButtonsW = decrButtonW + incrButtonW;
- float trackW = (float)(sbSize.width - (sbInsetsW + sbButtonsW));
- float min = (float)sb.getMinimum();
- float extent = (float)sb.getVisibleAmount();
- float range = (float)sb.getMaximum() - min;
- float value = (float)sb.getValue();
- int thumbW = range <= 0.0F ? this.getMaximumThumbSize().width : (int)(trackW * (extent / range));
- thumbW = Math.max(thumbW, this.getMinimumThumbSize().width);
- thumbW = Math.min(thumbW, this.getMaximumThumbSize().width);
- int thumbX = incrButtonX - thumbW;
- if (sb.getValue() < sb.getMaximum() - sb.getVisibleAmount()) {
- float thumbRange = trackW - (float)thumbW;
- thumbX = (int)(0.5F + thumbRange * ((value - min) / (range - extent)));
- thumbX += decrButtonX + decrButtonW;
- }
-
- int sbAvailButtonW = sbSize.width - sbInsetsW;
- if (sbAvailButtonW < sbButtonsW) {
- incrButtonW = decrButtonW = sbAvailButtonW / 2;
- incrButtonX = sbSize.width - (sbInsets.right + incrButtonW);
- }
-
- this.decrButton.setBounds(decrButtonX, itemY, decrButtonW, itemH);
- this.incrButton.setBounds(incrButtonX, itemY, incrButtonW, itemH);
- int itrackX = decrButtonX + decrButtonW;
- int itrackW = incrButtonX - itrackX;
- this.trackRect.setBounds(itrackX, itemY, itrackW, itemH);
- if (thumbW >= (int)trackW) {
- this.setThumbBounds(0, 0, 0, 0);
- } else {
- if (thumbX + thumbW > incrButtonX) {
- thumbX = incrButtonX - thumbW;
- }
-
- if (thumbX < decrButtonX + decrButtonW) {
- thumbX = decrButtonX + decrButtonW + 1;
- }
-
- this.setThumbBounds(thumbX, itemY, thumbW, itemH);
- }
-
- }
-
- protected void layoutVScrollbar(JScrollBar sb) {
- Dimension sbSize = ((Component)sb).getSize();
- Insets sbInsets = ((JComponent)sb).getInsets();
- int itemW = sbSize.width - (sbInsets.left + sbInsets.right);
- int itemX = sbInsets.left;
- int decrButtonH = this.decrButton.getPreferredSize().height;
- int decrButtonY = sbInsets.top;
- int incrButtonH = this.incrButton.getPreferredSize().height;
- int incrButtonY = sbSize.height - (sbInsets.bottom + incrButtonH);
- int sbInsetsH = sbInsets.top + sbInsets.bottom;
- int sbButtonsH = decrButtonH + incrButtonH;
- float trackH = (float)(sbSize.height - (sbInsetsH + sbButtonsH));
- float min = (float)sb.getMinimum();
- float extent = (float)sb.getVisibleAmount();
- float range = (float)sb.getMaximum() - min;
- float value = (float)sb.getValue();
- int thumbH = range <= 0.0F ? this.getMaximumThumbSize().height : (int)(trackH * (extent / range));
- thumbH = Math.max(thumbH, this.getMinimumThumbSize().height);
- thumbH = Math.min(thumbH, this.getMaximumThumbSize().height);
- int thumbY = incrButtonY - thumbH;
- if (sb.getValue() < sb.getMaximum() - sb.getVisibleAmount()) {
- float thumbRange = trackH - (float)thumbH;
- thumbY = (int)(0.5F + thumbRange * ((value - min) / (range - extent)));
- thumbY += decrButtonY + decrButtonH;
- }
-
- int sbAvailButtonH = sbSize.height - sbInsetsH;
- if (sbAvailButtonH < sbButtonsH) {
- incrButtonH = decrButtonH = sbAvailButtonH / 2;
- incrButtonY = sbSize.height - (sbInsets.bottom + incrButtonH);
- }
-
- this.decrButton.setBounds(itemX, decrButtonY, itemW, decrButtonH);
- this.incrButton.setBounds(itemX, incrButtonY, itemW, incrButtonH);
- int itrackY = decrButtonY + decrButtonH;
- int itrackH = incrButtonY - itrackY;
- this.trackRect.setBounds(itemX, itrackY, itemW, itrackH);
- if (thumbH >= (int)trackH) {
- this.setThumbBounds(0, 0, 0, 0);
- } else {
- if (thumbY + thumbH > incrButtonY) {
- thumbY = incrButtonY - thumbH;
- }
-
- if (thumbY < decrButtonY + decrButtonH) {
- thumbY = decrButtonY + decrButtonH + 1;
- }
-
- this.setThumbBounds(itemX, thumbY, itemW, thumbH);
- }
-
- }
-
- public Dimension minimumLayoutSize(Container scrollbarContainer) {
- return this.getMinimumSize((JComponent)scrollbarContainer);
- }
-
- public void paint(Graphics g, JComponent c) {
- this.paintTrack(g, c, this.getTrackBounds());
- this.paintThumb(g, c, this.getThumbBounds());
- }
-
- protected void paintDecreaseHighlight(Graphics g) {
- Insets insets = this.scrollbar.getInsets();
- Rectangle thumbR = this.getThumbBounds();
- g.setColor(trackHighlightColor);
- if (this.scrollbar.getOrientation() == 1) {
- int x = insets.left;
- int y = this.decrButton.getY() + this.decrButton.getHeight();
- int w = this.scrollbar.getWidth() - (insets.left + insets.right);
- int h = thumbR.y - y;
- g.fillRect(x, y, w, h);
- } else {
- int x = this.decrButton.getX() + this.decrButton.getHeight();
- int y = insets.top;
- int w = thumbR.x - x;
- int h = this.scrollbar.getHeight() - (insets.top + insets.bottom);
- g.fillRect(x, y, w, h);
- }
-
- }
-
- protected void paintIncreaseHighlight(Graphics g) {
- Insets insets = this.scrollbar.getInsets();
- Rectangle thumbR = this.getThumbBounds();
- g.setColor(trackHighlightColor);
- if (this.scrollbar.getOrientation() == 1) {
- int x = insets.left;
- int y = thumbR.y + thumbR.height;
- int w = this.scrollbar.getWidth() - (insets.left + insets.right);
- int h = this.incrButton.getY() - y;
- g.fillRect(x, y, w, h);
- } else {
- int x = thumbR.x + thumbR.width;
- int y = insets.top;
- int w = this.incrButton.getX() - x;
- int h = this.scrollbar.getHeight() - (insets.top + insets.bottom);
- g.fillRect(x, y, w, h);
- }
-
- }
-
- protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) {
- if (!thumbBounds.isEmpty() && this.scrollbar.isEnabled()) {
- int w = thumbBounds.width;
- int h = thumbBounds.height;
- g.translate(thumbBounds.x, thumbBounds.y);
- g.setColor(thumbDarkShadowColor);
- g.drawRect(0, 0, w - 1, h - 1);
- g.setColor(thumbColor);
- g.fillRect(0, 0, w - 1, h - 1);
- g.setColor(thumbHighlightColor);
- g.drawLine(1, 1, 1, h - 2);
- g.drawLine(2, 1, w - 3, 1);
- g.setColor(thumbLightShadowColor);
- g.drawLine(2, h - 2, w - 2, h - 2);
- g.drawLine(w - 2, 1, w - 2, h - 3);
- g.translate(-thumbBounds.x, -thumbBounds.y);
- }
- }
-
- protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds) {
- g.setColor(trackColor);
- g.fillRect(trackBounds.x, trackBounds.y, trackBounds.width, trackBounds.height);
- if (this.trackHighlight == 1) {
- this.paintDecreaseHighlight(g);
- } else if (this.trackHighlight == 2) {
- this.paintIncreaseHighlight(g);
- }
-
- }
-
- public Dimension preferredLayoutSize(Container scrollbarContainer) {
- return this.getPreferredSize((JComponent)scrollbarContainer);
- }
-
- public void removeLayoutComponent(Component child) {
- }
-
- protected void scrollByBlock(int direction) {
- synchronized(this.scrollbar){}
-
- try {
- int oldValue = this.scrollbar.getValue();
- int blockIncrement = this.scrollbar.getBlockIncrement(direction);
- int delta = blockIncrement * (direction > 0 ? 1 : -1);
- this.scrollbar.setValue(oldValue + delta);
- this.trackHighlight = direction > 0 ? 2 : 1;
- Rectangle dirtyRect = this.getTrackBounds();
- this.scrollbar.repaint(dirtyRect.x, dirtyRect.y, dirtyRect.width, dirtyRect.height);
- } catch (Throwable var8) {
- throw var8;
- }
-
- }
-
- protected void scrollByUnit(int direction) {
- synchronized(this.scrollbar){}
-
- try {
- int delta;
- if (direction > 0) {
- delta = this.scrollbar.getUnitIncrement(direction);
- } else {
- delta = -this.scrollbar.getUnitIncrement(direction);
- }
-
- this.scrollbar.setValue(delta + this.scrollbar.getValue());
- } catch (Throwable var5) {
- throw var5;
- }
-
- }
-
- protected void setThumbBounds(int x, int y, int width, int height) {
- if (this.thumbRect.x != x || this.thumbRect.y != y || this.thumbRect.width != width || this.thumbRect.height != height) {
- int minX = Math.min(x, this.thumbRect.x);
- int minY = Math.min(y, this.thumbRect.y);
- int maxX = Math.max(x + width, this.thumbRect.x + this.thumbRect.width);
- int maxY = Math.max(y + height, this.thumbRect.y + this.thumbRect.height);
- this.thumbRect.setBounds(x, y, width, height);
- this.scrollbar.repaint(minX, minY, maxX - minX, maxY - minY);
- }
- }
-
- public void uninstallUI(JComponent c) {
- this.scrollTimer.stop();
- this.scrollTimer = null;
- if (this.decrButton != null) {
- this.decrButton.removeMouseListener(this.buttonListener);
- }
-
- if (this.incrButton != null) {
- this.incrButton.removeMouseListener(this.buttonListener);
- }
-
- this.scrollbar.getModel().removeChangeListener(this.modelListener);
- this.scrollbar.removeMouseListener(this.trackListener);
- this.scrollbar.removeMouseMotionListener(this.trackListener);
- this.scrollbar.remove(this.incrButton);
- this.scrollbar.remove(this.decrButton);
- this.scrollbar.setLayout((LayoutManager)null);
- this.thumbRect = null;
- this.incrButton = null;
- this.decrButton = null;
- this.scrollbar = null;
- }
- }
-